import java.util.LinkedHashMap;
import java.util.Map;


public class P14 {
	//public static Map<Long, Long> map = new LinkedHashMap<Long, Long>();
	
	public static void main(String[] args) {
		long maxCount = 0;
		long maxChainNumber = 0;
		
		for (long i = 1; i < 1000000; i++) {
			System.out.println(i);
			long count = getChainCount(i);
			
			//map.put(i, count);
			
			if (maxCount < count) {
				maxCount = count;
				maxChainNumber = i;
			}
		}
		
		System.out.println("maxChainNumber:" + maxChainNumber);
		System.out.println("maxCount:" + maxCount);
	}
	
	private static long getChainCount(long num) {
		int count = 1;
		
		while (num != 1) {
//			if (map.containsKey(num)) {
//				count += map.get(num);
//				break;
//			} else {
				num = getNextTerm(num);
				count++;
			//}
		}
		
		return count;

	}
	
	private static long getNextTerm(long num) {	
		if (num%2 == 0) {
			return num/2;
		} else {
			return 3*num + 1;
		}
	}
}
